import React, { Component } from 'react'

const Child2 = (props) => {
  const clickHandle = () => {
    setTimeout(() => {
      alert(props.name);
    }, 3000);
  };

  return (
    <>
      <div>{props.name}</div>
      <div onClick={clickHandle}>click me child2</div>
    </>
  );
}

class Child1 extends Component {
  clickHandle = () => {
    setTimeout(() => {
      alert(this.props.name);
    }, 3000);
  }
  render() {
    return (
      <>
        <div>{this.props.name}</div>
        <div onClick={this.clickHandle}>click me child1</div>
      </>
    );
  }
}

export default class rcc extends Component {
  constructor(props) {
    super(props);

    this.state = {
      name: 'gmonking',
    };
  }
  clickHandle = () => {
    this.setState({
      name: 'gmonking111111',
    });
  }
  render() {
    return (
      <div>
        <Child1 name={this.state.name} />
        <Child2 name={this.state.name} />

        <div onClick={this.clickHandle}>click me parent</div>
      </div>
    )
  }
}
